package com.db.product.controller;

import com.db.core.dto.PageDto;
import com.db.core.vo.PageResult;
import com.db.core.vo.Result;
import com.db.deviceType.dto.DeviceTypePageDto;
import com.db.product.dto.ProductPageDto;
import com.db.product.entity.Product;
import com.db.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author vodka
 * @since 2023-10-27
 */
@RestController
@CrossOrigin
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    //分页查询
    @PostMapping("page")
    public PageResult page(@RequestBody ProductPageDto productPageDto){
        return productService.page(productPageDto);
    }

    //产品查询
    @RequestMapping("list")
    public Result selectAll(){
        List<Product> productList = productService.list();
        return new Result<>(0,"success",productList);
    }

    //产品增加
    @RequestMapping("insert")
    public Result insert(@RequestBody Product product) {
        boolean save = productService.save(product);
        return new Result(0, "success",save);
    }


    //产品修改
    @RequestMapping("update")
    public Result update(@RequestBody Product product) {
        boolean save = productService.updateById(product);
        return new Result(0, "success",save);
    }

    //产品删除
    @GetMapping("delete/{productId}")
    public Result delete(@PathVariable Long productId) {
        boolean save = productService.removeById(productId);
        return new Result(0, "success",save);
    }






}
